$avatar-sizes: (
  16: (
    font-size: 10px,
    line-height: 16px,
    border-radius: $border-radius-small
  ),
  18: (
    border-radius: $border-radius-small
  ),
  20: (
    border-radius: $border-radius-small
  ),
  24: (
    font-size: 12px,
    line-height: 24px,
    border-radius: $border-radius-default
  ),
  26: (
    font-size: 20px,
    line-height: 1.33,
    border-radius: $border-radius-default
  ),
  32: (
    font-size: 14px,
    line-height: 32px,
    border-radius: $border-radius-default
  ),
  40: (
    font-size: 16px,
    line-height: 38px,
    border-radius: $border-radius-default
  ),
  48: (
    font-size: 20px,
    line-height: 48px,
    border-radius: $border-radius-large
  ),
  60: (
    font-size: 32px,
    line-height: 60px,
    border-radius: $border-radius-large
  ),
  64: (
    font-size: 28px,
    line-height: 64px,
    border-radius: $border-radius-large
  ),
  90: (
    font-size: 36px,
    line-height: 90px,
    border-radius: $border-radius-large
  ),
  96: (
    font-size: 36px,
    line-height: 94px,
    border-radius: $border-radius-large
  ),
  100: (
    font-size: 36px,
    line-height: 98px,
    border-radius: $border-radius-large
  ),
  160: (
    font-size: 96px,
    line-height: 158px,
    border-radius: $border-radius-large
  )
);

.avatar,
.avatar-container {
  float: left;
  margin-right: $gl-padding;
  border-radius: $avatar-radius;

  @each $size, $size-config in $avatar-sizes {
    &.s#{$size} {
      @include avatar-size(#{$size}px, if($size < 48, 8px, 16px));
    }
  }
}

.avatar {
  transition-property: none;
  width: 40px;
  height: 40px;
  padding: 0;
  background: $gray-lightest;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba($gray-950, $gl-avatar-border-opacity);

  &.avatar-inline {
    float: none;
    display: inline-block;
    margin-left: 2px;
    flex-shrink: 0;

    &.s16,
    &.s24 {
      margin-right: 4px;
    }
  }

  &.center {
    font-size: 14px;
    line-height: 1.8em;
    text-align: center;
  }

  &.avatar-tile {
    border-radius: 0;
    border: 0;
  }
}

.identicon {
  text-align: center;
  vertical-align: top;
  color: $gray-900;
  background-color: $gray-50;

  // Sizes
  @each $size, $size-config in $avatar-sizes {
    $keys: map-keys($size-config);

    &.s#{$size} {
      @each $key in $keys {
        // We don't want `border-radius` to be included here.
        @if ($key != 'border-radius') {
          #{$key}: map-get($size-config, #{$key});
        }
      }
    }
  }

  // Background colors
  @for $i from 1 through length($gl-avatar-identicon-bgs) {
    &.bg#{$i} {
      background-color: nth($gl-avatar-identicon-bgs, $i);
    }
  }
}

.avatar-container {
  overflow: hidden;
  display: flex;

  a {
    width: 100%;
    height: 100%;
    display: flex;
    text-decoration: none;
  }

  .avatar {
    border-radius: 0;
    border: 0;
    height: auto;
    width: 100%;
    margin: 0;
    align-self: center;
  }

  &.s40 {
    min-width: 40px;
    min-height: 40px;
  }

  &.s64 {
    min-width: 64px;
    min-height: 64px;
  }
}

.rect-avatar {
  border-radius: $border-radius-small;

  @each $size, $size-config in $avatar-sizes {
    &.s#{$size} {
      border-radius: map-get($size-config, 'border-radius');

      .avatar {
        border-radius: map-get($size-config, 'border-radius');
      }
    }
  }
}

.avatar-counter {
  @include avatar-counter();
}

.user-popover {
  // GlAvatarLabeled doesn't expose any prop to override internal classes

  // Max width of popover container is set by gl-max-w-48
  // so we need to ensure that name/username/status container doesn't overflow
  .gl-avatar-labeled-labels {
    max-width: px-to-rem(290px);
  }

  .gl-avatar-labeled-label,
  .gl-avatar-labeled-sublabel {
    @include gl-text-truncate;
  }

  &.user-popover-cannot-merge {
    .popover-header {
      @include gl-bg-orange-50;
    }
  }
}
